part of '../../repository.dart';

const _kGooglePlayOneTimePurchasedItemRevokedKey = 'revoked';
const _kGooglePlayOneTimePurchasedItemTransactionKey = 'transaction';

const _kGooglePlayOneTimePurchasedItemTypeValue = 'one_time_purchased_item';

class _GooglePlayOneTimePurchasedItemDto extends Equatable implements _GooglePlayPurchasedItemDto {
  const _GooglePlayOneTimePurchasedItemDto._internal({
    required this.purchaseItemSku,
    required this.purchaseToken,
    required this.revoked,
    required this.transactionDto,
  });

  @override
  final String purchaseItemSku;

  @override
  final String purchaseToken;

  final bool revoked;
  final _GooglePlayOneTimePurchasedItemTransactionDto transactionDto;

  @override
  List<Object?> get props {
    return [
      purchaseItemSku,
      purchaseToken,
      revoked,
      transactionDto,
    ];
  }

  factory _GooglePlayOneTimePurchasedItemDto.fromJson(Map<String, dynamic> json) {
    final transactionJson =
        json[_kGooglePlayOneTimePurchasedItemTransactionKey] as Map<String, dynamic>;
    final transactionDto = _GooglePlayOneTimePurchasedItemTransactionDto.fromJson(transactionJson);

    return _GooglePlayOneTimePurchasedItemDto._internal(
      purchaseItemSku: json[_kGooglePlayPurchasedItemPurchaseItemSkuKey],
      purchaseToken: json[_kGooglePlayPurchasedItemPurchaseTokenKey],
      revoked: json[_kGooglePlayOneTimePurchasedItemRevokedKey],
      transactionDto: transactionDto,
    );
  }

  @override
  GooglePlayOneTimePurchasedItem toEntity() {
    return GooglePlayOneTimePurchasedItem(
      purchaseItemSku: purchaseItemSku,
      purchaseToken: purchaseToken,
      revoked: revoked,
      transaction: transactionDto.toEntity(),
    );
  }
}
